//
//  GERootTabBarController.m
//  GPurchase
//
//  Created by limei.li on 2017/5/10.
//  Copyright © 2017年 gta Education. All rights reserved.
//

#import "GERootTabBarController.h"
#import "GEHomeViewController.h"
#import "GEProductsViewController.h"
#import "GEProfileViewController.h"
#import "GERootNavController.h"

@interface GERootTabBarController ()<UITabBarDelegate>


    
@end

@implementation GERootTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addChildViewControllers];
    
}

    /**
     *  添加子控制器
     */
- (void)addChildViewControllers
    {
        //添加home控制器
        GEHomeViewController *home = [[GEHomeViewController alloc] init];
        [self addViewController:home title:@"主页" imageName:@"tabBar_home"];
        //添加product控制器
        GEProductsViewController *product = [[GEProductsViewController alloc] init];
        [self addViewController:product title:@"产品" imageName:@"tabBar_product"];
        //添加profile控制器
        GEProfileViewController *profile = [[GEProfileViewController alloc] init];
        [self addViewController:profile title:@"我的" imageName:@"tabBar_profile"];
        
    }


    //设置子控制器
- (void)addViewController:(UIViewController *)controller title:(NSString *)title  imageName:(NSString *)imageName
    {
        controller.title = title;
        //需要原图显示
        controller.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        controller.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_hightlighted",imageName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //文字的颜色需要定制
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], NSForegroundColorAttributeName, nil]forState:UIControlStateNormal];
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil]forState:UIControlStateSelected];
        
        GERootNavController *navController = [[GERootNavController alloc] initWithRootViewController:controller];
        navController.navigationBar.translucent = NO;
        [self addChildViewController:navController];
        
    }

- (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    
}


@end
